import React, { memo } from 'react'
import { Table } from 'antd'
import { useTranslation } from 'react-i18next'

const TableIndex = (props: any) => {
  const { t } = useTranslation()
  const { rowKey, columns, dataSource, total, pageObj, pageSizeOptions, handlePageChange, rowSelection } = props

  return (
    <Table
      style={{ marginTop: '20px' }}
      bordered
      rowKey={rowKey}
      // 设置勾选
      rowSelection={rowSelection}
      columns={columns}
      dataSource={dataSource}
      pagination={{
        // 设置总条数
        total: total || 0,
        // 设置页码可选项
        pageSizeOptions: pageSizeOptions,
        // 显示总条数
        showTotal: (totalAll: number) => `${t('total')} ${totalAll} ${t('items')}`,
        // 显示位置
        position: ['bottomCenter'],
        current: pageObj.pageNum,
        pageSize: pageObj.pageSize,
        //是否可以快速跳转至某页
        showQuickJumper: true,
        // 是否可以改变 pageSize
        showSizeChanger: true,
        // 修改页码回调
        onChange: (pageNum: number, pageSize: number) => {
          handlePageChange(pageNum, pageSize)
        }
      }}
    ></Table>
  )
}

export default memo(TableIndex)
